import os
import numpy as np
import pandas as pd
from pandas.io.excel import ExcelWriter
from docx import Document

import openpyxl
from openpyxl import load_workbook
from openpyxl.styles import Font
from openpyxl.styles import Alignment
from openpyxl.styles import Border, Side
from openpyxl.chart import BarChart, Reference

import tkinter
import tkinter.messagebox
import customtkinter

def rsshot():
    filename = 'Учебное поручение 1 семестр очное Кафедра прикладной математики.docx'

    document = Document(filename)
    tables = document.tables

    df_tables = []
    for table in tables:
        df = [['' for i in range(len(table.columns))] for j in range(len(table.rows))]
        for i, row in enumerate(table.rows):
            for j, cell in enumerate(row.cells):
                if cell.text:
                    df[i][j] = cell.text
        df_tables.append(pd.DataFrame(df))

    o1 = df_tables[0]

    o1 = o1[3:]  # удаляем строки

    o1.drop(o1.loc[:, [0, 2, 5, 7, 8, 9, 10, 11, 12, 14, 20, 24, 25, 26, 27, 29, 30, 31, 32, 35, 36, 37]],
            axis=1,  # удаляем столбцы
            inplace=True
            )

    o1.columns = o1.iloc[0]

    o1.insert(0, "Семестр", 1)
    o1.insert(1, "Форма обучения", "очная")
    o1.insert(13, "Контрольная работа", "")

    o1.drop(len(o1) + 2,
            axis=0,  # удаляем итого
            inplace=True
            )

    o1 = o1[1:]  # удаляем певую строку (дубль заголовков)

    columns_names = ('Семестр', 'Форма обучения', 'Индекс группы', 'Б',
                     'В/Б', 'Предмет', 'Лекции',
                     'Лаб. зан.', 'Практ.  зан.', 'Консульт. пред экз.', 'Экзамен',
                     'Зачет', 'Текущий контроль', 'Контр. раб.', 'Учебн. прак.',
                     'Производств. практ.', 'Курс. раб.', 'ГК(экз.)', 'ГК(кв.раб.)',
                     'Итого')

    o1.columns = columns_names

    filename = 'Учебное поручение 1 семестр заочное Кафедра прикладной математики.docx'

    document = Document(filename)
    tables = document.tables

    df_tables = []
    for table in tables:
        df = [['' for i in range(len(table.columns))] for j in range(len(table.rows))]
        for i, row in enumerate(table.rows):
            for j, cell in enumerate(row.cells):
                if cell.text:
                    df[i][j] = cell.text
        df_tables.append(pd.DataFrame(df))

    z1 = df_tables[0]

    z1 = z1[3:]  # удаляем строки

    z1.drop(z1.loc[:, [0, 2, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15, 17, 25, 26, 27, 28, 29, 30, 31]],
            axis=1,  # удаляем столбцы
            inplace=True
            )

    z1.columns = z1.iloc[0]

    z1.insert(0, "Семестр", 1)
    z1.insert(1, "Форма обучения", "заочная")
    z1.insert(14, "учебная прак.", "")
    z1.insert(15, "Производств. практика", "")
    z1.insert(16, "Курс. работа", "")

    z1.drop(len(z1) + 2,
            axis=0,  # удаляем итого
            inplace=True
            )

    z1 = z1[1:]  # удаляем певую строку (дубль заголовков)

    z1.columns = columns_names

    filename = 'Учебное поручение 1 семестр очно-заочное Кафедра прикладной математики.docx'

    document = Document(filename)
    tables = document.tables

    df_tables = []
    for table in tables:
        df = [['' for i in range(len(table.columns))] for j in range(len(table.rows))]
        for i, row in enumerate(table.rows):
            for j, cell in enumerate(row.cells):
                if cell.text:
                    df[i][j] = cell.text
        df_tables.append(pd.DataFrame(df))

    oz1 = df_tables[0]

    oz1 = oz1[3:]  # удаляем строки

    oz1.drop(oz1.loc[:, [0, 2, 6, 7, 8, 9, 10, 11, 12, 13, 14, 25, 26, 27, 28, 30, 31, 32, 33, 36, 37, 38]],
             axis=1,  # удаляем столбцы
             inplace=True
             )

    oz1.columns = oz1.iloc[0]

    oz1.insert(0, "Семестр", 1)
    oz1.insert(1, "Форма обучения", "очно-заочная")

    oz1.drop(len(oz1) + 2,
             axis=0,  # удаляем итого
             inplace=True
             )

    oz1 = oz1[1:]  # удаляем певую строку (дубль заголовков)

    oz1.columns = columns_names

    filename = 'Учебное поручение 2 семестр очное Кафедра прикладной математики.docx'

    document = Document(filename)
    tables = document.tables

    df_tables = []
    for table in tables:
        df = [['' for i in range(len(table.columns))] for j in range(len(table.rows))]
        for i, row in enumerate(table.rows):
            for j, cell in enumerate(row.cells):
                if cell.text:
                    df[i][j] = cell.text
        df_tables.append(pd.DataFrame(df))

    o2 = df_tables[0]

    o2 = o2[3:]  # удаляем строки

    o2.drop(o2.loc[:, [0, 2, 5, 7, 8, 9, 10, 11, 12, 14, 20, 24, 25, 26, 27, 29, 30, 31, 32, 35, 36, 37]],
            axis=1,  # удаляем столбцы
            inplace=True
            )

    o2.columns = o2.iloc[0]

    o2.insert(0, "Семестр", 2)
    o2.insert(1, "Форма обучения", "очная")
    o2.insert(13, "Контрольная работа", "")

    o2.drop(len(o2) + 2,
            axis=0,  # удаляем итого
            inplace=True
            )

    o2 = o2[1:]  # удаляем певую строку (дубль заголовков)

    o2.columns = columns_names

    filename = 'Учебное поручение 2 семестр заочное Кафедра прикладной математики.docx'

    document = Document(filename)
    tables = document.tables

    df_tables = []
    for table in tables:
        df = [['' for i in range(len(table.columns))] for j in range(len(table.rows))]
        for i, row in enumerate(table.rows):
            for j, cell in enumerate(row.cells):
                if cell.text:
                    df[i][j] = cell.text
        df_tables.append(pd.DataFrame(df))

    z2 = df_tables[0]

    z2 = z2[3:]  # удаляем строки

    z2.drop(z2.loc[:, [0, 2, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15, 17, 25, 26, 27, 28, 29, 30, 31]],
            axis=1,  # удаляем столбцы
            inplace=True
            )

    z2.columns = z2.iloc[0]

    z2.insert(0, "Семестр", 2)
    z2.insert(1, "Форма обучения", "заочная")
    z2.insert(14, "учебная прак.", "")
    z2.insert(15, "Производств. практика", "")
    z2.insert(16, "Курс. работа", "")

    z2.drop(len(z2) + 2,
            axis=0,  # удаляем итого
            inplace=True
            )

    z2 = z2[1:]  # удаляем певую строку (дубль заголовков)

    z2.columns = columns_names

    filename = 'Учебное поручение 2 семестр очно-заочное Кафедра прикладной математики.docx'

    document = Document(filename)
    tables = document.tables

    df_tables = []
    for table in tables:
        df = [['' for i in range(len(table.columns))] for j in range(len(table.rows))]
        for i, row in enumerate(table.rows):
            for j, cell in enumerate(row.cells):
                if cell.text:
                    df[i][j] = cell.text
        df_tables.append(pd.DataFrame(df))

    oz2 = df_tables[0]

    oz2 = oz2[3:]  # удаляем строки

    oz2.drop(oz2.loc[:, [0, 2, 6, 7, 8, 9, 10, 11, 12, 13, 14, 25, 26, 27, 28, 30, 31, 32, 33, 36, 37, 38]],
             axis=1,  # удаляем столбцы
             inplace=True
             )

    oz2.columns = oz2.iloc[0]

    oz2.insert(0, "Семестр", 2)
    oz2.insert(1, "Форма обучения", "очно-заочная")

    oz2.drop(len(oz2) + 2,
             axis=0,  # удаляем итого
             inplace=True
             )

    oz2 = oz2[1:]  # удаляем певую строку (дубль заголовков)

    oz2.columns = columns_names

    n = pd.concat([o1, z1], ignore_index=True)
    n = pd.concat([n, oz1], ignore_index=True)
    n = pd.concat([n, o2], ignore_index=True)
    n = pd.concat([n, z2], ignore_index=True)
    n = pd.concat([n, oz2], ignore_index=True)

    n = n.sort_values(['Семестр', 'Предмет'])

    n.to_excel(r'Нагрузка.xlsx', sheet_name="Вся нагрузка", index=False)

    with ExcelWriter(r'Нагрузка.xlsx', mode="a") as writer:
        n.to_excel(writer, sheet_name="Не распр. дисциплины", index=False)


    wb = load_workbook('Нагрузка.xlsx')
    sheet = wb["Вся нагрузка"]

    sheet['A1'].alignment = Alignment(text_rotation=90, horizontal='center', vertical="center")
    sheet['B1'].alignment = Alignment(text_rotation=90, horizontal='center', vertical="center")
    sheet['C1'].alignment = Alignment(text_rotation=90, horizontal='center', vertical="center")
    sheet['D1'].alignment = Alignment(text_rotation=90, horizontal='center', vertical="center")
    sheet['E1'].alignment = Alignment(text_rotation=90, horizontal='center', vertical="center")
    sheet['F1'].alignment = Alignment(text_rotation=90, horizontal='center', vertical="center")
    sheet['G1'].alignment = Alignment(text_rotation=90, horizontal='center', vertical="center")
    sheet['H1'].alignment = Alignment(text_rotation=90, horizontal='center', vertical="center")
    sheet['I1'].alignment = Alignment(text_rotation=90, horizontal='center', vertical="center")
    sheet['J1'].alignment = Alignment(text_rotation=90, horizontal='center', vertical="center")
    sheet['K1'].alignment = Alignment(text_rotation=90, horizontal='center', vertical="center")
    sheet['L1'].alignment = Alignment(text_rotation=90, horizontal='center', vertical="center")
    sheet['M1'].alignment = Alignment(text_rotation=90, horizontal='center', vertical="center")
    sheet['N1'].alignment = Alignment(text_rotation=90, horizontal='center', vertical="center")
    sheet['O1'].alignment = Alignment(text_rotation=90, horizontal='center', vertical="center")
    sheet['P1'].alignment = Alignment(text_rotation=90, horizontal='center', vertical="center")
    sheet['Q1'].alignment = Alignment(text_rotation=90, horizontal='center', vertical="center")
    sheet['R1'].alignment = Alignment(text_rotation=90, horizontal='center', vertical="center")
    sheet['S1'].alignment = Alignment(text_rotation=90, horizontal='center', vertical="center")
    sheet['T1'].alignment = Alignment(text_rotation=90, horizontal='center', vertical="center")

    sheet.column_dimensions['A'].width = 7
    sheet.column_dimensions['B'].width = 13
    sheet.column_dimensions['C'].width = 13
    sheet.column_dimensions['D'].width = 3
    sheet.column_dimensions['E'].width = 3
    sheet.column_dimensions['F'].width = 60
    sheet.column_dimensions['G'].width = 4
    sheet.column_dimensions['H'].width = 4
    sheet.column_dimensions['I'].width = 4
    sheet.column_dimensions['J'].width = 4
    sheet.column_dimensions['K'].width = 4
    sheet.column_dimensions['L'].width = 4
    sheet.column_dimensions['M'].width = 4
    sheet.column_dimensions['N'].width = 4
    sheet.column_dimensions['O'].width = 4
    sheet.column_dimensions['P'].width = 4
    sheet.column_dimensions['Q'].width = 4
    sheet.column_dimensions['R'].width = 4
    sheet.column_dimensions['S'].width = 4
    sheet.column_dimensions['T'].width = 4

    for i in range(2, (len(n) + 6)):
        for j in range(1, 21):
            if j == 2 or j == 3 or j == 6:
                pass
            else:
                a2 = sheet.cell(row=i, column=j)
                a2.alignment = Alignment(horizontal='center', vertical="center")

    wb.save('Нагрузка.xlsx')

rsshot()

def str_spisok_update():
    excel_data_df = pd.read_excel('Нагрузка.xlsx', sheet_name='Не распр. дисциплины',
                                  usecols=['Семестр', 'Индекс группы', 'Итого', 'Предмет'])

    for ind in excel_data_df.index:
        #s.ljust(5)
        excel_data_df.loc[ind, 'Индекс группы'] = excel_data_df.loc[ind, 'Индекс группы'].ljust(25)
        excel_data_df.loc[ind, 'Предмет'] = excel_data_df.loc[ind, 'Предмет'].ljust(300)
        #excel_data_df.loc[ind, 'Академические группы'] = '{0: <25}'.format(excel_data_df.loc[ind, 'Академические группы'])
        #excel_data_df.loc[ind, 'Наименование дисциплины'] = '{0: <300}'.format(excel_data_df.loc[ind, 'Наименование дисциплины'])
        excel_data_df.loc[ind, 'Итого'] = '{0: <10}'.format(excel_data_df.loc[ind, 'Итого'])
        #excel_data_df.loc[ind, 'Итого'] = excel_data_df.loc[ind, 'Итого'].ljust(10)

    str_spisok = []
    for ind in excel_data_df.index:
        str_spisok.append('   {}    {}{}{}'.format(excel_data_df.loc[ind, 'Семестр'], excel_data_df.loc[ind, 'Индекс группы'], excel_data_df.loc[ind, 'Итого'], excel_data_df.loc[ind, 'Предмет']))
    return str_spisok


customtkinter.set_appearance_mode("Light")
customtkinter.set_default_color_theme("blue")

app = customtkinter.CTk()
app.title("Расчёт индивидуальной загрузки преподавателей")
app.geometry(f"{1280}x{720}")

app.grid_columnconfigure(1, weight=1)
app.grid_columnconfigure((2), weight=0)
app.grid_rowconfigure((1, 2), weight=1)

# Боковая рамка
sidebar_frame = customtkinter.CTkFrame(app, width=140, corner_radius=0)
sidebar_frame.grid(row=0, column=0, rowspan=3, sticky="nsew")
sidebar_frame.grid_rowconfigure(4, weight=1)
logo_label = customtkinter.CTkLabel(sidebar_frame, text="МФ ЧелГУ", font=customtkinter.CTkFont(size=20, weight="bold"))
logo_label.grid(row=0, column=0, padx=20, pady=(20, 10))
opt_men_lable = customtkinter.CTkLabel(sidebar_frame, text="Выбрать преподавателя:",)
opt_men_lable.grid(row=1, column=0, padx=20, pady=(20, 10))


list_prep_table = pd.read_excel('Преподавательский состав.xlsx')
val = list_prep_table['ФИО'].tolist()
val = np.array(val,dtype=str)

def optionmenu_callback(choice):
    print("optionmenu dropdown clicked:", choice)
    global ch
    ch = choice

optionmenu_var = customtkinter.StringVar(value="Новый преподаватель")
optionmenu = customtkinter.CTkOptionMenu(sidebar_frame,values=val,
                                         command=optionmenu_callback,
                                         variable=optionmenu_var)
optionmenu.grid(row=2, column=0, padx=20, pady=(20, 10))

checkboxes = []
def checkbox_event():
    check = []# индексы нажатых
    for i in range(len(checkboxes)):
        if checkboxes[i].get() == 1:
            check.append(i)
    len_check = len(check)
    #print(len_check)

    #entry.get() - то что в текстовом поле
    #Создаём ноый лист преподавателя
    name = entry.get()
    prep_iz_list=0
    if optionmenu.get() != 'Новый преподаватель':
        name = optionmenu.get()
        prep_iz_list = 1

    list = pd.read_excel('Нагрузка.xlsx', sheet_name='Не распр. дисциплины')
    new_prep = list.iloc[check]
    with ExcelWriter(r'Нагрузка.xlsx', mode="a") as writer:
        new_prep.to_excel(writer, sheet_name=name, index=False)

    wb = load_workbook('Нагрузка.xlsx')
    sheet = wb[name]

    sheet[f'G{len_check + 2}'] = f'= SUM(G5:G{len_check + 4})'
    sheet[f'H{len_check + 2}'] = f'= SUM(H5:H{len_check + 4})'
    sheet[f'I{len_check + 2}'] = f'= SUM(I5:I{len_check + 4})'
    sheet[f'J{len_check + 2}'] = f'= SUM(J5:J{len_check + 4})'
    sheet[f'K{len_check + 2}'] = f'= SUM(K5:K{len_check + 4})'
    sheet[f'L{len_check + 2}'] = f'= SUM(L5:L{len_check + 4})'
    sheet[f'M{len_check + 2}'] = f'= SUM(M5:M{len_check + 4})'
    sheet[f'N{len_check + 2}'] = f'= SUM(N5:N{len_check + 4})'
    sheet[f'O{len_check + 2}'] = f'= SUM(O5:O{len_check + 4})'
    sheet[f'P{len_check + 2}'] = f'= SUM(P5:P{len_check + 4})'
    sheet[f'Q{len_check + 2}'] = f'= SUM(Q5:Q{len_check + 4})'
    sheet[f'R{len_check + 2}'] = f'= SUM(R5:R{len_check + 4})'
    sheet[f'S{len_check + 2}'] = f'= SUM(S5:S{len_check + 4})'
    sheet[f'T{len_check + 2}'] = f'= SUM(T5:T{len_check + 4})'

    sheet[f'V{len_check + 1}'] = 'Сумма по строке'
    sheet[f'V{len_check + 2}'] = f'= SUM(G{len_check + 5}:S{len_check + 5})'
    sheet[f'V{len_check + 3}'] = 'Сумма по столбцу'
    sheet[f'V{len_check + 4}'] = f'= SUM(T5:T{len_check + 4})'

    sheet['A1'].alignment = Alignment(text_rotation=90, horizontal='center', vertical="center")
    sheet['B1'].alignment = Alignment(text_rotation=90, horizontal='center', vertical="center")
    sheet['C1'].alignment = Alignment(text_rotation=90, horizontal='center', vertical="center")
    sheet['D1'].alignment = Alignment(text_rotation=90, horizontal='center', vertical="center")
    sheet['E1'].alignment = Alignment(text_rotation=90, horizontal='center', vertical="center")
    sheet['F1'].alignment = Alignment(text_rotation=90, horizontal='center', vertical="center")
    sheet['G1'].alignment = Alignment(text_rotation=90, horizontal='center', vertical="center")
    sheet['H1'].alignment = Alignment(text_rotation=90, horizontal='center', vertical="center")
    sheet['I1'].alignment = Alignment(text_rotation=90, horizontal='center', vertical="center")
    sheet['J1'].alignment = Alignment(text_rotation=90, horizontal='center', vertical="center")
    sheet['K1'].alignment = Alignment(text_rotation=90, horizontal='center', vertical="center")
    sheet['L1'].alignment = Alignment(text_rotation=90, horizontal='center', vertical="center")
    sheet['M1'].alignment = Alignment(text_rotation=90, horizontal='center', vertical="center")
    sheet['N1'].alignment = Alignment(text_rotation=90, horizontal='center', vertical="center")
    sheet['O1'].alignment = Alignment(text_rotation=90, horizontal='center', vertical="center")
    sheet['P1'].alignment = Alignment(text_rotation=90, horizontal='center', vertical="center")
    sheet['Q1'].alignment = Alignment(text_rotation=90, horizontal='center', vertical="center")
    sheet['R1'].alignment = Alignment(text_rotation=90, horizontal='center', vertical="center")
    sheet['S1'].alignment = Alignment(text_rotation=90, horizontal='center', vertical="center")
    sheet['T1'].alignment = Alignment(text_rotation=90, horizontal='center', vertical="center")

    sheet.column_dimensions['A'].width = 7
    sheet.column_dimensions['B'].width = 13
    sheet.column_dimensions['C'].width = 13
    sheet.column_dimensions['D'].width = 3
    sheet.column_dimensions['E'].width = 3
    sheet.column_dimensions['F'].width = 60
    sheet.column_dimensions['G'].width = 4
    sheet.column_dimensions['H'].width = 4
    sheet.column_dimensions['I'].width = 4
    sheet.column_dimensions['J'].width = 4
    sheet.column_dimensions['K'].width = 4
    sheet.column_dimensions['L'].width = 4
    sheet.column_dimensions['M'].width = 4
    sheet.column_dimensions['N'].width = 4
    sheet.column_dimensions['O'].width = 4
    sheet.column_dimensions['P'].width = 4
    sheet.column_dimensions['Q'].width = 4
    sheet.column_dimensions['R'].width = 4
    sheet.column_dimensions['S'].width = 4
    sheet.column_dimensions['T'].width = 4

    sheet.insert_rows(0, 3)

    a2 = sheet.cell(row=2, column=1)
    a2.value = "Ф.И.О."

    b2 = sheet.cell(row=2, column=2)
    b2.value = name

    a2 = sheet.cell(row=2, column=7)
    a2.value = "Должность"

    if prep_iz_list == 1:
        a2 = sheet.cell(row=2, column=10)
        for i in range (len(list_prep_table)):
            if list_prep_table.iloc[i]['ФИО'] == ch:
                a = i
        a2.value = list_prep_table.iloc[a]['Должность']

    a2 = sheet.cell(row=2, column=16)
    a2.value = "Ставка"

    if prep_iz_list == 1:
        a2 = sheet.cell(row=2, column=18)
        for i in range (len(list_prep_table)):
            if list_prep_table.iloc[i]['ФИО'] == ch:
                a = i
        a2.value = list_prep_table.iloc[a]['Ставка']

    a2 = sheet.cell(row=1, column=16)
    a2.value = "2024-2025 уч.год"

    a2 = sheet.cell(row=len_check+7, column=3)
    a2.value = "Согласовано"

    a2 = sheet.cell(row=len_check+7, column=6)
    a2.value = "Преподаватель ________________________"

    a2 = sheet.cell(row=len_check+7, column=8)
    a2.value = "Зав.кафедрой ________________________"

    a2 = sheet.cell(row=(len_check+5), column=6)
    a2.value = "Итого:"
    sheet[f'F{len_check + 5}'].font = Font(bold=True)
    sheet[f'G{len_check + 5}'].font = Font(bold=True)
    sheet[f'H{len_check + 5}'].font = Font(bold=True)
    sheet[f'I{len_check + 5}'].font = Font(bold=True)
    sheet[f'J{len_check + 5}'].font = Font(bold=True)
    sheet[f'K{len_check + 5}'].font = Font(bold=True)
    sheet[f'L{len_check + 5}'].font = Font(bold=True)
    sheet[f'M{len_check + 5}'].font = Font(bold=True)
    sheet[f'N{len_check + 5}'].font = Font(bold=True)
    sheet[f'O{len_check + 5}'].font = Font(bold=True)
    sheet[f'P{len_check + 5}'].font = Font(bold=True)
    sheet[f'Q{len_check + 5}'].font = Font(bold=True)
    sheet[f'R{len_check + 5}'].font = Font(bold=True)
    sheet[f'S{len_check + 5}'].font = Font(bold=True)
    sheet[f'T{len_check + 5}'].font = Font(bold=True)
    for i in range(5, (len_check + 5)):
        sheet[f'T{i}'].font = Font(bold=True)
    sheet[f'F{len_check + 5}'].alignment = Alignment(horizontal='right')

    thins = Side(border_style="thin", color="000000")
    for i in range(4, (len_check + 6)):
        for j in range(1, 21):
            a2 = sheet.cell(row=i, column=j)
            a2.border = Border(top=thins, left=thins, right=thins, bottom=thins,)

    for i in range(5, (len_check + 6)):
        for j in range(1, 21):
            if j == 2 or j == 3 or j == 6:
                pass
            else:
                a2 = sheet.cell(row=i, column=j)
                a2.alignment = Alignment(horizontal='center', vertical="center")

    wb.save('Нагрузка.xlsx')

    #удаляем старый список нераспределённых дисциплин
    wb = openpyxl.load_workbook('Нагрузка.xlsx')
    pfd = wb['Не распр. дисциплины']
    wb.remove(wb['Не распр. дисциплины'])
    wb.save('Нагрузка.xlsx')

    list = list.drop(check)
    with ExcelWriter(r'Нагрузка.xlsx', mode="a") as writer:
        list.to_excel(writer, sheet_name='Не распр. дисциплины', index=False)

    #обновляем страничку
    checkboxes.clear()
    entry.delete(0, 100)
    update_list(checkboxes)

    optionmenu.set('Новый преподаватель')

# Текстовое поле и кнопка
entry = customtkinter.CTkEntry(app, placeholder_text="Введите ФИО преподавателя")
entry.grid(row=0, column=1, columnspan=1, padx=(20, 0), pady=(20, 20), sticky="nsew")

main_button_1 = customtkinter.CTkButton(app, text="Записать", fg_color="transparent",
                                        border_width=2, text_color=("gray10", "#DCE4EE"), command=checkbox_event)
main_button_1.grid(row=0, column=2, padx=(20, 20), pady=(20, 20), sticky="nsew")

def update_list(checkboxes = []):
    str_spisok = str_spisok_update()

    Scrollable_Frame = customtkinter.CTkScrollableFrame(app)
    Scrollable_Frame.grid(row=1, column=1, rowspan=3, padx=(20, 0), pady=(0, 20), sticky="nsew")

    for i in range(len(str_spisok_update())):
        checkbox = customtkinter.CTkCheckBox(Scrollable_Frame, text=str_spisok[i])
        checkbox.grid(row=i, column=0, padx=10, pady=(5, 0), sticky="w")

        checkboxes.append(checkbox)

update_list(checkboxes)

app.mainloop()
